package com.mzj.saas.mservice.property.service;

import com.mzj.saas.mservice.property.entity.EstateRepairsEvaluation;
import com.mzj.saas.mservice.property.repository.EstateRepairsEvaluationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * @author hikari
 * @since 2021-05-20
 */
@Service
public class EstateRepairsEvaluationService {
	@Autowired
    private JdbcTemplate jdbcTemplate;
	@Autowired
    private EstateRepairsEvaluationRepository estateRepairsEvaluationRepository;

    public EstateRepairsEvaluation findByRepairsId(Long id) {
        return estateRepairsEvaluationRepository.findBByRepairsId(id);
    }

    public boolean isExist(Long repairsId) {
        String sql = "SELECT COUNT(*) FROM saas_estate_repairs_evaluation WHERE repairs_id = ?";
        Integer count = jdbcTemplate.queryForObject(sql, Integer.class, repairsId);

        if (count != null) {
            return count > 0;
        } else {
            return false;
        }
    }

    public EstateRepairsEvaluation save(EstateRepairsEvaluation estateRepairsEvaluation) {
        return estateRepairsEvaluationRepository.save(estateRepairsEvaluation);
    }
}
